package com.kws.merchant.controller;


import com.alibaba.fastjson.JSONObject;
import com.kws.merchant.domain.Contract;
import com.kws.merchant.domain.ContractReplenish;
import com.kws.merchant.domain.po.ContractPo;
import com.kws.merchant.domain.po.CreateContractPo;
import com.kws.merchant.domain.po.SignLinkPo;
import com.kws.merchant.service.ContractReplenishService;
import com.kws.merchant.service.ContractService;
import com.kws.system.api.domain.QuerySignUrlRq;
import com.kws.system.api.domain.ResultDto;
import com.kws.system.api.domain.SignFlowRevoke;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 合同管理-合同(Contract)表控制层
 *
 * @author yxy
 * @since 2024-10-29 15:37:30
 */
@RestController
@Api(tags = "合同管理-合同(Contract)")
@RequestMapping("contract")
public class ContractController {
    /**
     * 服务对象
     */
    @Resource
    private ContractService contractService;
    @Autowired
    private ContractReplenishService contractReplenishService;
 
    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<Contract>> pageList(@RequestBody ContractPo contractPo){
        return R.ok(contractService.pageList(contractPo));
    }



    @PostMapping("/createContract")
    @ApiOperation(value = "创建合同--前端无需调用创建合同接口，生成订单时自动调用,这里只有大商品才会存在合同")
    public R createContract(@RequestBody CreateContractPo createContractPo) {
        return R.ok(contractService.createContract(createContractPo));
    }


    @PostMapping("/signLink")
    @ApiOperation(value = "查询签署链接")
    public R signLink(@RequestBody SignLinkPo signLinkPo) {
        return R.ok(contractService.signLink(signLinkPo));
    }


    @GetMapping("/fileDownloadUrl/{signFlowId}")
    @ApiOperation(value = "下载已签署完成文件--未签署完成的文件不可下载")
    public R fileDownloadUrl(@PathVariable("signFlowId") String signFlowId) {
        return R.ok(contractService.fileDownloadUrl(signFlowId));
    }


    @GetMapping("/signViewLink/{signFlowId}")
    @ApiOperation(value = "查看合同--免登录，任何人可查看")
    public R signViewLink(@PathVariable("signFlowId") String signFlowId) {
        return R.ok(contractService.signViewLink(signFlowId));
    }

    @PostMapping("callBackUrl")
    @ApiOperation(value = "回调通知-修改合同状态")
    public R callBackUrl(@RequestBody JSONObject json) {
        return R.ok(contractService.callBackUrl(json));
    }

    @ApiOperation("撤销签署流程")
    @PostMapping("/signFlowRevoke")
    public R signFlowRevoke(@RequestBody SignFlowRevoke signFlowRevoke){
        return R.ok(contractService.signFlowRevoke(signFlowRevoke));
    }
}
